﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="spread_spreader.aspx.cs" Inherits="backmanage_spreadsystem_spread_spreader" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>推广员系统</title>
    <script type="text/javascript" src="../js/jquery1.6.2.js"></script>
	<script type="text/javascript" src="../external/jquery.bgiframe-2.1.2.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.core.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.widget.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.mouse.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.button.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.draggable.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.position.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.resizable.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.dialog.js"></script> 
	<script type="text/javascript" src="../js/jquery.effects.core.js"></script> 
	<script type="text/javascript" src="../js/jquery.ajax.upfile.js"></script>
    <link rel="stylesheet" href="../css/demos.css" />
    <link rel="stylesheet" href="../css/jquery.ui.all.css" />
    <script type="text/javascript">
    $(function(){
        $("#dialog-form").dialog("destory"); 
                var username = $( "#username" ),
				    name = $( "#name" ),
				    tel=$("#tel"),
				    allFields = $( [] ).add( username ).add( name ).add(tel),
				    tips = $( ".validateTips" );
                function updateTips(t)
                {
                  tips.text(t)	
                      .addClass("ui-state-highlight");
                  setTimeout(function(){
                      tips.removeClass("ui-state-highlight",1500);
                  },500);
                }
                function checkEmpty(e,n)
                {
                  if(e.val().length>0){
                     return true;}
                  else{
                     e.addClass("ui-state-error");
                     updateTips(n+"不能为空.");
                     return false;
                     }
                }
                function EmptyText()
                {
                  $("#username").val("");
                  $("#name").val("");
                  $("#tel").val("");
                  $("#imgurl").attr("src","#");
                }
                function SpreaderAdd()
                {
                  var username=$("#username").val();
                  var name=$("#name").val();
                  var tel=$("#tel").val();
                  var image=$("#imgurl").attr("src");
                  $.ajax({
                        async:false,
                        url:'../API/A_Spreader.aspx',
                        type:'POST',
                        data:{
                              edit:'add',
                              username:username,
                              name:name,
                              tel:tel,
                              image:image
                        },
                        dataType:'json',
                        success:function(data)
                        {
                          if(data.err=='ok')
                          {
                            return true;
                          }
                          if(data.err=='no')
                          {
                            return false;
                          }
                        }
                  });
                }
                function SpreaderList()
                {
                  $.ajax({
                        async:true,
                        url:'../API/A_Spreader.aspx',
                        type:'POST',
                        data:{edit:'list'},
                        success:function(msg)
                        {
                           $("#spreaderlist tbody").text("");
                           $("#spreaderlist tbody").append(msg);
                        }
                  });
                }
                $("#dialog-form").dialog({
                        autoOpen:false,
                        height:370,
                        width:450,
                        modal:true,
                        buttons:{
                                 "提交":function(){
                                       var flag=true;
                                       allFields.removeClass("ui-state-error");
                                       
                                       flag=flag && checkEmpty(username,"推广员账户");
                                       flag=flag && checkEmpty(name,"推广员姓名");
                                       flag=flag && checkEmpty(tel,"推广员电话");
                                       
                                       if(flag)
                                       {
                                            SpreaderAdd();
                                            EmptyText();
                                         	$(this).dialog("close");
                                       }
                                 },
                                 "取消":function(){$(this).dialog("close");},
                                 },
                               close:function(){allFields.val("").removeClass("ui-state-error");},
               });
         $("#create-user").button().click(function(){$("#dialog-form").dialog("open");});
         function ajaxFileUpload()
               {
                    $.ajaxFileUpload(
                                   {
                                url:'../API/A_Fileupload.aspx?uptype=1',            
                                secureuri:false,
                                fileElementId:'fup',
                                data:{uptype:'1'},
                                dataType: 'json',                                  
                                success: function (data, status)
                                {
                                    if(data.err=="")
                                    {
                                        document.getElementById("imgurl").src=data.msg;
                                    }
                                    else
                                    {
                                        alert(data.err);
                                    }
                                },
                                error: function (data, status, e)
                                {
                                    alert("上传失败!");
                                }
                            });
               }
                $("#upfile").click(function(){ajaxFileUpload();});
                $(document).ready(function(){SpreaderList();});
    })
    </script>
    <style type="text/css">
        body { font-size: 62.5%; }
		label, input { display:block;}
		input.text { margin-bottom:12px; width:95%; padding: .4em; }
		fieldset { padding:0; border:0; margin-top:25px; }
		h1 { font-size: 1.2em; margin: .6em 0; }
		div#users-contain { width: 350px; margin: 20px 0; }
		div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
		div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
		.ui-dialog .ui-state-error { padding: .3em; }
    	.validateTips { border:1px transparent solid; padding: 0.3em; }
		.validateTips input{border:1}
		.text{border:1}
		div#img-size{ width:200px}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    推广员系统
    <a id="create-user">添加推广员</a>
    <div id="dialog-form" title="添加推广员">
    <p class="validateTips">填写要添加的推广员信息.</p> 
    <fieldset>
       <label for="username">推广员账号</label>
       <input type="text" name="username" id="username" class="text ui-widget-content ui-corner-all" />
       <br/>
       <label for="name">推广员姓名</label>
       <input type="text" name="name" id="name" value="" class="text ui-widget-content ui-corner-all" />
       <br />
       <label for="tel">推广员电话</label>
       <input type="text" name="tel" id="tel" value="" class="text ui-widget-content ui-corner-all" />
       <br />
       <label for="img">图片信息</label>
       <div><input type="file" name="fup" id="fup" style="float:left" /><input type="button" name="upfile" id="upfile" value="上传" style="float:left" /></div>
       <br />
       <br />
       <img alt="图片信息" name="imgurl" id="imgurl" src="" style="float:none;" />
    </fieldset>
    </div>
    <table id="spreaderlist" name="spreaderlist">
      <thead>
        <tr>
           <td>推广员</td>
           <td>联系方式</td>
           <td>操作</td>
        </tr>
      </thead>
      <tbody>
      </tbody>
      <tfoot>
        <tr>
          <td colspan="3">一共#页 第一页</td>
        </tr>
      </tfoot>
    </table>
    </div>
    </form>
</body>
</html>
